import {getStorageSync, removeStorage, setStorage} from "@tarojs/taro";

class Storage {
    constructor() {
    }


    get<T>(key: string): T {
        return getStorageSync(key);
    }


    set<T>(name: string, value: T): Promise<boolean> {
        return new Promise(resolve => {
            setStorage({
                key: name,
                data: value,
                success: () => {
                    resolve(true)
                },
                fail: () => {
                    resolve(false)
                }
            }).then(() => {
            });
        })
    }

    remove(key: string): Promise<boolean> {
        return new Promise(resolve => {
            removeStorage({
                key,
                success: () => {
                    resolve(true)
                }
            }).then(() => {
            });
        })
    }

}

export default new Storage();
